package com.tjsinfo.tjsoa.workplan.bo;

import java.util.List;

import com.tjsinfo.tjsoa.common.ToolKit;
import com.tjsinfo.tjsoa.system.vo.TSystemUser;
//import com.tjsinfo.tjsoa.workplan.dao.IHibernateWorkPlanExamineDao;
import com.tjsinfo.tjsoa.workplan.dao.IWorkPlanExamineDao;
import com.tjsinfo.tjsoa.workplan.dao.WorkPlanExamineDao;
import com.tjsinfo.tjsoa.workplan.vo.WorkPlanExamine;
import com.tjsinfo.tjsoa.workplan.vo.WorkPlanMain;

public class WorkPlanExamineBo implements IWorkPlanExamineBo{

	private IWorkPlanExamineDao workPlanExamineDao;
	final Integer daipishi = 0;
	private final Integer yipishi = 1;
	final Boolean starttrue = true;
	final Boolean startfalse = false;

	public IWorkPlanExamineDao getWorkPlanExamineDao() {
		return workPlanExamineDao;
	}

	public void setWorkPlanExamineDao(IWorkPlanExamineDao workPlanExamineDao) {
		this.workPlanExamineDao = workPlanExamineDao;
	}

	/* (non-Javadoc)
	 * @see com.tjsinfo.tjsoa.workplan.bo.IWorkPlanExamineBo#delete(com.tjsinfo.tjsoa.workplan.vo.WorkPlanExamine)
	 */
	public void delete(WorkPlanExamine workPlanExamine) {
		// TODO Auto-generated method stub
		workPlanExamineDao.delete(workPlanExamine);
	}

	/* (non-Javadoc)
	 * @see com.tjsinfo.tjsoa.workplan.bo.IWorkPlanExamineBo#save(com.tjsinfo.tjsoa.workplan.vo.WorkPlanExamine)
	 */
	public String save(WorkPlanExamine workPlanDefine) {
		// TODO Auto-generated method stub
		return workPlanExamineDao.save(workPlanDefine);
	}

	/* (non-Javadoc)
	 * @see com.tjsinfo.tjsoa.workplan.bo.IWorkPlanExamineBo#update(com.tjsinfo.tjsoa.workplan.vo.WorkPlanExamine)
	 */
	public void update(WorkPlanExamine workPlanDefine) {
		// TODO Auto-generated method stub
		workPlanExamineDao.update(workPlanDefine);
	}
	
	/**
	 * 添加工作计划时上报工作计划

	 * 上报人

	 * 上报计划ID
	 */
	public boolean addShangBaoRen(String shangbaoren,String jihuaid)
	{
		try {
			String[] strarrry =	ToolKit.splitString(shangbaoren);
			if (strarrry[0] != null) {
				for (String string : strarrry) {
					WorkPlanExamine workPlanExamine = new WorkPlanExamine();
					workPlanExamine.setExamineState(daipishi);
					WorkPlanMain planMain = new WorkPlanMain();
					planMain.setId(jihuaid);
					workPlanExamine.setWorkPlanMain(planMain);
					TSystemUser tjsUser = new TSystemUser();
					tjsUser.setUserId(Integer.parseInt(string));
					workPlanExamine.setTjsUser(tjsUser);
					workPlanExamine.setExamineContent("");
					workPlanExamineDao.save(workPlanExamine);
					
				}
				
			} else {
				;
			}
		} catch (NumberFormatException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return startfalse;
		}
		return startfalse;
	}
	/**
	 * 检查突然上报的工作计划
	 * @param 领导ID
	 * @param 状态

	 * @return
	 */
	public List selectSuddenlyWorkPlan(Integer userid ,Integer start)
	{
		return 	workPlanExamineDao.selectSuddenlyWorkPlan(userid, start);
	}
	/**
	 * 根据用户ID和计划ID查询工作计划批示
	 * @param 用户ID
	 * @param 计划ID
	 * @return
	 */
	public WorkPlanExamine selectWorkPlan(Integer userid,String jihuaid)
	{
		return workPlanExamineDao.selectWorkPlan(userid, jihuaid);
	}
	/**
	 * 保持领导的审批意见

	 * @param 用户ID
	 * @param 计划ID
	 * @param 内容
	 * @return
	 */
	public boolean saveORupdateWorkPlan(Integer userid,String jihuaid,String value)
	{
		try {
			WorkPlanExamine workPlanExamine =new WorkPlanExamine();
			/*if (workPlanExamine != null ) {
				workPlanExamine.setExamineContent(value);
				workPlanExamine.setExamineState(1);
				workPlanExamineDao.update(workPlanExamine);
			} else {
				workPlanExamine = new WorkPlanExamine();*/
				workPlanExamine.setExamineContent(value);
				workPlanExamine.setExamineState(1);
				TSystemUser tjsUser = new TSystemUser();
				tjsUser.setUserId(userid);
				workPlanExamine.setTjsUser(tjsUser);
				WorkPlanMain workPlanMain = new WorkPlanMain();
				workPlanMain.setId(jihuaid);
				workPlanExamine.setWorkPlanMain(workPlanMain);
				workPlanExamineDao.save(workPlanExamine);
			//}
			return starttrue;
		} catch (RuntimeException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return startfalse;
		}
		
	}
}
